from django.shortcuts import render, redirect, reverse
from .models import LearnRecommend, RecommendTpye


# Create your views here.
def get_learn_recommend(request):
    return redirect(reverse('learnType', args=['all']))


def get_type(request, type):
    items = LearnRecommend.objects.all()
    types = RecommendTpye.objects.all()
    type_list = []
    for item in types:
        type_list.append(item.type)

    if type != 'all':
        items = items.filter(type_id=types.get(type=type).id)
    return render(request, 'learnRecommend/learn.html', {
        "items": items,
        "type_list": type_list
    })
